package cn.zch.soft.util.process.current;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;

import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
/**
 * ManagementFactory是一个在运行时管理和监控Java VM的工厂类，它能提供很多管理VM的静态接口，比如RuntimeMXBean；
 * <p>
 * RuntimeMXBean是Java虚拟机的运行时管理接口.
 *
 * @author zchcpywin10
 * // @ Log
 */
@Slf4j
public class ProcessInfoCurrent {
  public static void main(String[] args) throws InterruptedException {
    getProcessId();
    Thread.sleep(30000);
  }
  public static int getProcessId() {
    RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean();
    int currentProcessId = Integer.parseInt(runtimeMxBean.getName().split("@")[0]);
    log.info("runtimeMxBean:{}", runtimeMxBean);
    log.info("getName:{}", runtimeMxBean.getName());
    log.info("SpecName():{}", runtimeMxBean.getSpecName());
    log.info("VmName():{}", runtimeMxBean.getVmName());
    log.info("BootClassPath():{}", runtimeMxBean.getBootClassPath());
    log.info("ClassPath():{}", runtimeMxBean.getClassPath());
    log.info("ObjectName():{}", runtimeMxBean.getObjectName());
    log.info("Class():{}", runtimeMxBean.getClass());
    log.info("SystemProperties():{}", runtimeMxBean.getSystemProperties());
    log.info("SystemProperties command():{}", runtimeMxBean.getSystemProperties().get("sun.java.command"));
    log.info("SystemPropertiesJSON():{}", JSON.toJSONString(runtimeMxBean.getSystemProperties()));
    log.info("runtimeMxBeanJSON():{}", JSON.toJSONString(runtimeMxBean));
    log.info("currentProcessId():{}", currentProcessId);
    return currentProcessId;
  }
}
